import { Component, _decorator } from "cc";
import { Tools } from "../../Util/Tools";
import SoundCtrl from "../../Ctrl/SoundCtrl";

const { ccclass, property } = _decorator;


export type DialogCallback = (dialog: Dialog) => void;

@ccclass
export default class Dialog extends Component {

    destroyCb: DialogCallback
    beforeDestroy: DialogCallback
    afterDestroy: DialogCallback

    setData(...data: any[]): Dialog {
        return this;
    }

    protected dialogDestroy() {

    }

    onDestroy() {
        try {
            if (this.destroyCb) {
                this.destroyCb(this)
            }
        } catch (error) {
            Tools.printError(error, "Dialog call destroyCb fail");
        }
        this.dialogDestroy();
    }

    close() {
        try {
            if (this.beforeDestroy) {
                this.beforeDestroy(this)
            }
        } catch (error) {
            Tools.printError(error, "Dialog call beforeClose fail");
        }
        this.node && this.node.destroy();
        try {
            if (this.afterDestroy) {
                this.afterDestroy(this)
            }
        } catch (error) {
            Tools.printError(error, "Dialog call afterClose fail");
        }
    }

}

Dialog["__name"] = "Dialog";
